<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-3-13
 * Time: 下午4:08
 */

namespace api\modules\chedai\tools;


use common\components\tools\Tools;
use yii\helpers\ArrayHelper;

class ApiTools
{
    /**
     * @param $data
     * @param $serialize_fields
     * @return mixed
     */
    public static function setSerializeApiField($data, $serialize_fields)
    {
        foreach ($data as $k => $v) {
            if (in_array($k, $serialize_fields)){
                $x = json_decode($v, true, 512);
                $data[$k] = serialize($x);
            }
        }
        return $data;
    }

    /**
     * @param $data
     * @param $serialize_fields
     * @return mixed
     */
    public static function showSerializeApiField($data, $serialize_fields)
    {
        foreach ($data as $k => $v) {
            if (in_array($k, $serialize_fields)){
                $data[$k] = unserialize($v);
            }
        }
        return $data;
    }
}